package com.pzhu.controller.wx;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pzhu.model.entity.Vip;
import com.pzhu.model.help.ResponseResult;
import com.pzhu.service.VipService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author : zqh
 * @Date : 2023/12/18 0018 下午 7:28
 * @Version: 1.0
 */
@Slf4j
@Api(tags = "小程序用户相关接口")
@RestController
@RequestMapping("/wx/vip")
public class WxVipController {

    @Autowired
    private VipService vipService;

    @ApiOperation("获取个人信息")
    @GetMapping("/getUser/{id}")
    @ApiImplicitParam(name = "id", value = "用户ID", required = true)
    public ResponseResult getInfo(@PathVariable(value = "id") Long id) {
        Vip vip = vipService.getOne(new LambdaQueryWrapper<Vip>().eq(Vip::getUserId, id));
        Map<String, Object> map = new HashMap<>();
        map.put("vip", vip);
        return ResponseResult.ok(map);
    }

    @ApiOperation("修改金额")
    @PostMapping("/update/money")
    public ResponseResult updateMoney(Long userId, BigDecimal price) {
        Vip vip = vipService.getOne(new LambdaQueryWrapper<Vip>().eq(Vip::getUserId, userId));
        vip.setPrice(vip.getPrice().add(price));
        vipService.updateById(vip);
        return ResponseResult.ok();
    }
}
